/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class RangeSumofBST {
	public int rangeSumBST(TreeNode root, int L, int R) {
		if (root == null) {
			return 0;
		}
		if (root.val < L) {
			return rangeSumBST(root.right, L, R);
		} else if (root.val > R) {
			return rangeSumBST(root.left, L, R);
		} else {
			return root.val + rangeSumBST(root.left, L, R) + rangeSumBST(root.right, L, R);
		}
	}

	class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
